
thr_pre_n_t = thr_pre_t(:,2:4); 
thr_post_n_t = thr_post_t(:,2:4);
thr_pre_f_t = thr_pre_t(:,1); 
thr_post_f_t = thr_post_t(:,1);

thr_pre_n_ct = thr_pre_ct(:,2:4); 
thr_post_n_ct = thr_post_ct(:,2:4);
thr_pre_f_ct = thr_pre_ct(:,1); 
thr_post_f_ct = thr_post_ct(:,1);

thr_pre_n_c = thr_pre_c(:,2:4); 
thr_post_n_c = thr_post_c(:,2:4);
thr_pre_f_c = thr_pre_c(:,1); 
thr_post_f_c = thr_post_c(:,1);


% Training
thr_pre_n_t_mean = mean(thr_pre_t(:,2:4),2);
thr_pre_n_t_mean_all = mean(thr_pre_n_t_mean)
thr_pre_n_t_se_all = std(thr_pre_n_t_mean)/sqrt(8)


thr_post_n_t_mean = mean(thr_post_t(:,2:4),2);
thr_post_n_t_mean_all = mean(thr_post_n_t_mean)
thr_post_n_t_se_all = std(thr_post_n_t_mean)/sqrt(8)


thr_pre_f_t_mean = mean(thr_pre_f_t)
thr_pre_f_t_se = std(thr_pre_f_t)/sqrt(8)

thr_post_f_t_mean = mean(thr_post_f_t)
thr_post_f_t_se = std(thr_post_f_t)/sqrt(8)

% Control-Training
thr_pre_n_ct_mean = mean(thr_pre_ct(:,2:4),2);
thr_pre_n_ct_mean_all = mean(thr_pre_n_ct_mean)
thr_pre_n_ct_se_all = std(thr_pre_n_ct_mean)/sqrt(8)

thr_post_n_ct_mean = mean(thr_post_ct(:,2:4),2);
thr_post_n_ct_mean_all = mean(thr_post_n_ct_mean)
thr_post_n_ct_se_all = std(thr_post_n_ct_mean)/sqrt(8)


thr_pre_f_ct_mean = mean(thr_pre_f_ct)
thr_pre_f_ct_se = std(thr_pre_f_ct)/sqrt(8)
thr_post_f_ct_mean = mean(thr_post_f_ct)
thr_post_f_ct_se = std(thr_post_f_ct)/sqrt(8)


% Control
thr_pre_n_c_mean = mean(thr_pre_c(:,2:4),2);
thr_pre_n_c_mean_all = mean(thr_pre_n_c_mean)
thr_pre_n_c_se_all = std(thr_pre_n_c_mean)/sqrt(8)

thr_post_n_c_mean = mean(thr_post_c(:,2:4),2);
thr_post_n_c_mean_all = mean(thr_post_n_c_mean)
thr_post_n_c_se_all = std(thr_post_n_c_mean)/sqrt(8)

thr_pre_f_c_mean = mean(thr_pre_f_c)
thr_pre_f_c_se = std(thr_pre_f_c)/sqrt(8)
thr_post_f_c_mean = mean(thr_post_f_c)
thr_post_f_c_se = std(thr_post_f_c)/sqrt(8)

% % colors = [211 57 33; 2 158 154]/255;

colors = [133 208 237 ; 114 180 114]/255
colors2 = colors*1.2;
colors2(colors2>1) = 1;

% colorsF2 = [0.9929 0.2682 0.1553; 0.0094 0.7435 0.7247; 0.9929 0.2682 0.1553; 0.0094 0.7435 0.7247; 0.9929 0.2682 0.1553; 0.0094 0.7435 0.7247];
colorsF2 = [0.6259 0.9788 1.0000; 0.5365 0.8471 0.5365; 0.6259 0.9788 1.0000; 0.5365 0.8471 0.5365; 0.6259 0.9788 1.0000; 0.5365 0.8471 0.5365];

%% Near distance
figure('color',[1 1 1])
% subplot(2,1,1)
subplot(1,2,1)

 ndata = [thr_pre_n_t_mean_all  thr_post_n_t_mean_all  thr_pre_n_ct_mean_all  thr_post_n_ct_mean_all  thr_pre_n_c_mean_all  thr_post_n_c_mean_all];
% % ndata1 = [thr_pre_n_t_mean_all   thr_pre_n_ct_mean_all   thr_pre_n_c_mean_all];
% % ndata2 = [thr_post_n_t_mean_all  thr_post_n_ct_mean_all  thr_post_n_c_mean_all];

ind_ndata_near = [thr_pre_n_t_mean  thr_post_n_t_mean thr_pre_n_ct_mean  thr_post_n_ct_mean  thr_pre_n_c_mean  thr_post_n_c_mean];
 se_ndata = [thr_pre_n_t_se_all thr_post_n_t_se_all  thr_pre_n_ct_se_all thr_post_n_ct_se_all  thr_pre_n_c_se_all thr_post_n_c_se_all];


%  xaxisF = [1 2 4 5 7 8];
 xaxisF = [1 1.4 4 4.4 7 7.4];

 errorbar(xaxisF, ndata,se_ndata, 'ko','MarkerFaceColor',[1 1 1],'linewidth',1, 'CapSize',0, 'MarkerSize',1);

for i = 1:6
    
    hold on
    
    plot(xaxisF(i),ndata(:,i),'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,colorsF2(i,:),'MarkerSize',10);
end

X = [1,4];
Y = [ndata(:,1),ndata(:,3)];
plot(X,Y,'.-k', 'linewidth',1)  

X = [4,7];
Y = [ndata(:,3),ndata(:,5)];
plot(X,Y,'.-k', 'linewidth',1)  



% X = [2,5];
X = [1.4,4.4];
Y = [ndata(:,2),ndata(:,4)];
plot(X,Y,'.-k', 'linewidth',1)  
% legend('pre','post')
% X = [5,8];
X = [4.4,7.4];
Y = [ndata(:,4),ndata(:,6)];
plot(X,Y,'.-k', 'linewidth',1) 


PP1 = plot (1, thr_pre_n_t_mean_all,'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.6259 0.9788 1.0000],'MarkerSize',10)
% PP2 = plot (2, thr_post_n_t_mean_all, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
PP2 = plot (1.4, thr_post_n_t_mean_all, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
% l = cell(1,2);
% l{1}='Pre'; l{2}='Post'; 
% [hLg, icons] = legend([P1,P2],l,'location','northwest');
% legend boxoff
PP3 = plot (4, thr_pre_n_ct_mean_all,'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.6259 0.9788 1.0000],'MarkerSize',10)
% PP4 = plot (5, thr_post_n_ct_mean_all, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
PP4 = plot (4.4, thr_post_n_ct_mean_all, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
PP5 = plot (7, thr_pre_n_c_mean_all,'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.6259 0.9788 1.0000],'MarkerSize',10)
% PP6 = plot (8, thr_post_n_c_mean_all, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
PP6 = plot (7.4, thr_post_n_c_mean_all, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)


% % break_axis('length', 0.1)
hold on
    

box off
ylabel('Size threshold (degree)');
% set(gca,'xlim',[0 8.5],'ylim',[0 3.5],'xtick',[1.5 4.5 7.5], 'xticklabel',{'Alternating', 'Fixed', 'Control'}, 'fontsize',10,'linewidth',1)
%  set(gca,'xlim',[0 8.5],'ylim',[1.4 2.2],'xtick',[1.5 4.5 7.5], 'xticklabel',{'Alternating', 'Fixed', 'Control'}, 'fontsize',10,'linewidth',1)
 set(gca,'xlim',[0 8.5],'ylim',[1.4 2.2],'xtick',[1.2 4.2 7.2], 'xticklabel',{'Alternating', 'Fixed', 'Control'}, 'FontName', 'Arial', 'fontsize',10,'linewidth',1)

% % set(gca,'xlim',[0 8.5],'ylim',[1.5 2.2],'xtick',[1.5 4.5 7.5], 'xticklabel',{'Alternating', 'Fixed', 'Control'},'yticklabel',{'0', '1.6', '1.7', '1.8', '1.9', '2',  '2.1', '2.2'}, 'fontsize',10,'linewidth',1)
title('Near distance')
hold on


%% Far distance
% subplot(2,1,2)
subplot(1,2,2)
% xaxisF = [1 2 4 5 7 8];
xaxisF = [1 1.4 4 4.4 7 7.4];

fdata = [thr_pre_f_t_mean  thr_post_f_t_mean  thr_pre_f_ct_mean thr_post_f_ct_mean   thr_pre_f_c_mean thr_post_f_c_mean];
ind_ndata_far = [thr_pre_f_t  thr_post_f_t thr_pre_f_ct  thr_post_f_ct  thr_pre_f_c  thr_post_f_c];
se_fdata = [thr_pre_f_t_se thr_post_f_t_se thr_pre_f_ct_se thr_post_f_ct_se thr_pre_f_c_se thr_post_f_c_se];


errorbar(xaxisF, fdata,se_fdata, 'ko','MarkerFaceColor',[1 1 1],'linewidth',1, 'CapSize',0, 'MarkerSize',1);

for i = 1:6

    hold on
    
    plot(xaxisF(i),fdata(:,i),'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,colorsF2(i,:),'MarkerSize',10);

end

% errorbar(xaxisF, fdata,se_fdata, 'ko','MarkerFaceColor',[1 1 1],'linewidth',1, 'CapSize',0, 'MarkerSize',1);

% plot (fdata(:,1), fdata(:,2))
% X = [1,2];
X = [1,4];
Y = [fdata(:,1),fdata(:,3)];
plot(X,Y,'.-k', 'linewidth',1)

X = [4,7];
Y = [fdata(:,3),fdata(:,5)]; 
plot(X,Y,'.-k', 'linewidth',1)  
hold on

% X = [2,5];
X = [1.4,4.5];
Y = [fdata(:,2),fdata(:,4)]; 
plot(X,Y,'.-k', 'linewidth',1) 


% X = [5,8];
X = [4.4,7.4];
Y = [fdata(:,4),fdata(:,6)];
plot(X,Y,'.-k', 'linewidth',1) 


P1 = plot (1, thr_pre_f_t_mean,'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.6259 0.9788 1.0000],'MarkerSize',10)
% P2 = plot (2, thr_post_f_t_mean, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
P2 = plot (1.4, thr_post_f_t_mean, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
l = cell(1,2);
l{1}='Pre'; l{2}='Post'; 
[hLg, icons] = legend([P1,P2],l,'location','northwest');
legend boxoff
P3 = plot (4, thr_pre_f_ct_mean,'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.6259 0.9788 1.0000],'MarkerSize',10)
% P4 = plot (5, thr_post_f_ct_mean, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
P4 = plot (4.4, thr_post_f_ct_mean, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
P5 = plot (7, thr_pre_f_c_mean,'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.6259 0.9788 1.0000],'MarkerSize',10)
% P6 = plot (8, thr_post_f_c_mean, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)
P6 = plot (7.4, thr_post_f_c_mean, 'o', 'MarkerEdgeColor' ,[0 0 0],'MarkerFaceColor' ,[0.5365 0.8471 0.5365],'MarkerSize',10)


hold on
box off
ylabel('Size threshold (degree)');
% set(gca,'xlim',[0 8.5],'ylim',[0.5 1.1],'xtick',[1.5 4.5 7.5], 'xticklabel',{'Alternating', 'Fixed', 'Control'}, 'fontsize',10,'linewidth',1)
set(gca,'xlim',[0 8.5],'ylim',[0.5 1.1],'xtick',[1.2 4.2 7.2], 'xticklabel',{'Alternating', 'Fixed', 'Control'},'FontName', 'Arial', 'fontsize',10,'linewidth',1)

title('Far distance')

% set(gcf,'units','centimeters','position',[0 0 19 9])

set(gcf,'units','centimeters','position',[0 0 24 9])

